package com.daohang361.imqq.ui.comboBox;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 * 
 */
public class ComplexJComboBoxRenderer implements ListCellRenderer {   
	
	  protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();   
	  
	  public Component getListCellRendererComponent(JList list, Object value, int index,   
	      boolean isSelected, boolean cellHasFocus) {   
	    Font theFont = null;   
	    Color theForeground = null;   
	    Icon theIcon = null;   
	    String theText = null;   
	  
	    JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,   
	        isSelected, cellHasFocus);   
	  
	    if (value instanceof JComboBoxItem) {   
	    	JComboBoxItem values = (JComboBoxItem) value;   
	      theFont = values.getFont();   
	      theForeground = values.getColor();   
	      theIcon = values.getImageIcon();   
	      theText = values.getQq();   
	    } else {   
	      theFont = list.getFont();   
	      theForeground = list.getForeground();   
	      theText = "";   
	    }   
	    if (!isSelected) {   
	      renderer.setForeground(theForeground);   
	    }   
	    if (theIcon != null) {   
	      renderer.setIcon(theIcon);   
	    }   
	    renderer.setText(theText);   
	    renderer.setFont(theFont);   
	    return renderer;   
	  }   
	}   